package com.sgb.auction.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
import com.luck.picture.lib.entity.LocalMedia;
import com.luck.picture.lib.tools.ScreenUtils;
import com.sgb.auction.R;
import com.sgb.auction.databinding.ActivityAuctionPublishBinding;
import com.sgb.auction.entity.AuctionPublishBean;
import com.sgb.auction.entity.MapLongAndLatEntity;
import com.sgb.auction.entity.PublishListBean;
import com.sgb.auction.viewmodule.AuctionPublishModel;
import com.sgb.auction.widget.SourcesFundAdapter;
import com.sgb.link.entity.BrandEntity;
import com.sgb.link.entity.GetSkuEntity;
import com.sgb.link.entity.PickFilterEntity;
import com.sgb.link.router.PathLogin;
import com.sgb.link.utils.JiCaiEditInputFilter;
import com.sgb.link.utils.ListToStringUtils;
import com.sgb.link.view.adapter.SelfTeamPicAdapter;
import com.sgb.link.view.widget.TwoLevelMultipleChoiceWindow;
import com.swgk.core.base.AppActivity;
import com.swgk.core.common.utils.ActivityJump;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.customview.PhotoViewActivity;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.CommonDialog;
import com.swgk.core.dialog.RoundCornerDialog;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.DateUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.view.CityPickBuilder;
import com.swgk.core.view.CityPickView;
import com.swgk.core.view.areapopup.AddressEntity;
import com.swgk.core.view.entity.GoodsPublishEntity;
import com.swgk.core.view.pop.GoodsTypePopWindow;
import com.swgk.core.view.entity.MenuEntity;
import java.io.File;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * Time:2021/11/19
 * AUTHOR:F_Q
 * Description:拍卖发布
 */
public class AuctionPublishActivity extends AppActivity implements ItemInputTextView.OnWholeItemClickListener {

    private AuctionPublishModel mModel;
    private ActivityAuctionPublishBinding mBinding;
    // 地址一级联动数据
    private List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> addressEntityList;
    // 地址二级联动数据
    private final List<List<AddressEntity<List<AddressEntity>>>> opt2 = new ArrayList<>();
    // 地址三级联动数据
    private final List<List<List<AddressEntity>>> opt3 = new ArrayList<>();
    private int cityPosition1;
    private int cityPosition2;
    private int cityPosition3;
    private String lat = "";
    private String lng = "";
    //商品类型
    private List<MenuEntity<MenuEntity<MenuEntity>>> goodsTypeEntityList;
    private AuctionPublishBean bean = new AuctionPublishBean();
    private AuctionPublishBean.RuleBean rulebean = new AuctionPublishBean.RuleBean();
    private AuctionPublishBean.CustomFieldBean customfieldbean = new AuctionPublishBean.CustomFieldBean();
    /***
     * 商品分类弹窗
     */
    private GoodsTypePopWindow goodsTypePopWindow;
    private SelfTeamPicAdapter mPicAdapter;
    private List<String> files;
    //sku属性信息
    private List<GetSkuEntity> skuList;
    private int SKULIST = 520134;

    private boolean isSku = false;
    private List<String> names;
    private List<PublishListBean> unitList;
    private List<PublishListBean> SourcesFundingList;
    private SourcesFundAdapter sourcesFundAdapter;
    private List<PickFilterEntity<List<PickFilterEntity>>> pickFilterList;
    private List<PickFilterEntity> listAll  = new ArrayList<>();
    private List<String> listaddress  = new ArrayList<>();;

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, AuctionPublishActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_auction_publish);
        mModel = new ViewModelProvider(this).get(AuctionPublishModel.class);
        mModel.setActivity(AuctionPublishActivity.this);
        mBinding.includeTitle.ivBack.setOnClickListener(v -> onBackPressed());
        mBinding.includeTitle.titleView.setText("拍卖发布");
        ViewOnClick();//初始化点击事件
        initPopWindow();//初始化商品弹窗信息
        imtvView();//图文描述模块view初始化
    }

    //初始化点击事件
    private void ViewOnClick() {
        mBinding.submit.setOnClickListener(this);//提交
        mBinding.cancel.setOnClickListener(this);//取消
        mBinding.basic.applyUnit.setOnWholeItemClickListener(this);//申请单位
        mBinding.basic.applyDepartment.setOnWholeItemClickListener(this);//申请部门
        mBinding.basic.address.setOnWholeItemClickListener(this);//地址
        mBinding.basic.detailedAddress.setOnWholeItemClickListener(this);//详细地址
        mBinding.detailed.shopType.setOnWholeItemClickListener(this);//商品类型
        mBinding.detailed.brand.setOnWholeItemClickListener(this);//品牌
        mBinding.detailed.measuringUnit.setOnWholeItemClickListener(this);//计量单位
        mBinding.detailed.specifications.setOnWholeItemClickListener(this);//商品规格
        mBinding.rules.isMargin.setOnWholeItemClickListener(this);//是否缴纳保证金
        mBinding.rules.marginPayment.setOnWholeItemClickListener(this);//保证金支付方式
        mBinding.rules.auctionStarttime.setOnWholeItemClickListener(this);//拍卖开始时间
        mBinding.rules.auctionEndtime.setOnWholeItemClickListener(this);//拍卖结束时间
        mBinding.rules.biddingStatus.setOnWholeItemClickListener(this);//竞买人身份
        mBinding.rules.publicBiddingName.setOnWholeItemClickListener(this);//是否公示竞买人名称
        mBinding.rules.bidderLimited.setOnWholeItemClickListener(this);//竞买人限定
        mBinding.rules.acceptArea.setOnWholeItemClickListener(this);//接受企业注册地区
        mBinding.rules.membersLevel.setOnWholeItemClickListener(this);//接受会员星级
        mBinding.rules.termsTime.setOnWholeItemClickListener(this);//货款支付时间
        mBinding.rules.termsPayment.setOnWholeItemClickListener(this);//货款支付方式
        mBinding.rules.transportType.setOnWholeItemClickListener(this);//运输方式
        mBinding.basic.auctionBasicField.setOnClickListener(this);//基础信息新增字段
        mBinding.detailed.auctionDetailedField.setOnClickListener(this);//标的物详情新增字段
        mBinding.rules.auctionRulesField.setOnClickListener(this);//拍卖规则新增字段
        //联系电话
        mBinding.basic.auctionPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
        //拍卖量auction_num
        mBinding.detailed.auctionNum.setInfilterType(ItemInputTextView.TYPE_NUMBER_DECIMAL);
        mBinding.detailed.auctionNum.setCheck(9, 4);
        //起拍价
        mBinding.rules.startPrice.setFilters(new JiCaiEditInputFilter[]{new JiCaiEditInputFilter(9999999999.99, 0.01, 2)});
        //加价幅度bid_increment
        mBinding.rules.bidIncrement.setFilters(new JiCaiEditInputFilter[]{new JiCaiEditInputFilter(9999999999.99, 0.01, 2)});
        //保留价
        mBinding.rules.keepPrice.setFilters(new JiCaiEditInputFilter[]{new JiCaiEditInputFilter(9999999999.99, 0.01, 2)});
        //评估价
        mBinding.rules.assessPrice.setFilters(new JiCaiEditInputFilter[]{new JiCaiEditInputFilter(9999999999.99, 0.01, 2)});
        //保证金支付方式-收款账户名称：margin_account_name、开户行：margin_bank、收款账户：margin_account
        //货款支付方式-收款账户名称：terms_account_name、开户行：terms_bank、收款账户：terms_account
        mBinding.rules.marginAccount.setInfilterType(ItemInputTextView.TYPE_NUM);
        mBinding.rules.termsAccount.setInfilterType(ItemInputTextView.TYPE_NUM);
        //竞买人身份
        mBinding.rules.biddingStatus.setContent("公司、个人皆可");
        //是否公示竞买人名称
        mBinding.rules.publicBiddingName.setContent("不公示");
        rulebean.setBidderIdentity("1");
        rulebean.setBidderNameIdentity("2");

    }

    @Override
    public void OnWholeItemClick(View view) {
        //申请单位
        if (view.getId() == R.id.apply_unit) {
            mModel.getCompanyList(view);
        }
        //申请部门
        if (view.getId() == R.id.apply_department) {
            if (TextUtils.isEmpty(mBinding.basic.applyUnit.getContent())) {
                MToast.showToast(this, "请选择申请单位");
                return;
            }
            mModel.getDepartmentList(bean.getApplyCompany(), view);
        }
        //地址
        if (view.getId() == R.id.address) {
            if (addressEntityList != null) {
                showCityPop();
            } else {
                mModel.getAddressModel();
            }
        }
        //详细地址
        if (view.getId() == R.id.detailed_address) {
            if (!TextUtils.isEmpty(mBinding.basic.address.getContent())) {
                Intent intent = new Intent();
                intent.setClass(this, AuctionMapAddressActivity.class);
                intent.putExtra(AuctionMapAddressActivity.TITLE, "详细地址");
                intent.putExtra(AuctionMapAddressActivity.HINT, "请输入地址");
                intent.putExtra(AuctionMapAddressActivity.SAVE_TEXT, "确定");
                intent.putExtra(AuctionMapAddressActivity.LATITUDE, Double.parseDouble(lat));
                intent.putExtra(AuctionMapAddressActivity.LONGTITUDE, Double.parseDouble(lng));
                startActivityForResult(intent, 255);
            } else {
                MToast.showToast(this, "请选择地址");
            }
        }
        //商品类型
        if (view.getId() == R.id.shop_type) {
            if (goodsTypeEntityList != null) {
                showGoodsTypePop();
            } else {
                mModel.getGoodsCategory();
            }
        }
        //品牌
        if (view.getId() == R.id.brand) {
            if (TextUtils.isEmpty(mBinding.detailed.shopType.getContent())) {
                MToast.showToast(this, "请选择商品类型");
                return;
            }
            mModel.getRangeBrandsList(bean.getCid(), view);
        }
        //计量单位
        if (view.getId() == R.id.measuring_unit) {
            if (unitList == null) {
                mModel.getUnitList(view);
            } else {
                showListPop("选择计量单位", view, unitList);
            }
        }
        //商品规格
        if (view.getId() == R.id.specifications) {
            if (skuList != null && skuList.size() > 0) {
                startActivityForResult(new Intent(this, AuctionSkuListActivity.class).putExtra("data", (Serializable) skuList), SKULIST);
            }
        }
        //是否缴纳保证金
        if (view.getId() == R.id.is_margin) {
            mModel.getIsmarginList(view);
        }
        //保证金支付方式
        if (view.getId() == R.id.margin_payment) {
            mModel.getPaymentList("保证金支付方式", view);
        }
        //拍卖开始时间
        if (view.getId() == R.id.auction_starttime) {
            showTimePop(view);
        }
        //拍卖结束时间
        if (view.getId() == R.id.auction_endtime) {
            if (TextUtils.isEmpty(mBinding.rules.auctionStarttime.getContent())) {
                MToast.showToast(this, "请选择拍卖开始时间");
                return;
            }
            showTimePop(view);
        }
        //竞买人身份
        if (view.getId() == R.id.bidding_status) {
            mModel.getBiddingStatusList(view);
        }
        //是否公示竞买人名称
        if (view.getId() == R.id.public_bidding_name) {
            mModel.getBiddingPublicList(view);
        }
        //竞买人限定
        if (view.getId() == R.id.bidder_limited) {
            if (SourcesFundingList == null) {
                mModel.getBidderLimitedlicList();
            } else {
                showMultiselect();

            }
        }
        //接受企业注册地区
        if (view.getId() == R.id.accept_area) {
            if (pickFilterList==null||pickFilterList.size()==0){
                mModel.getAcceptAreaList();
            }else {
               TwoLevelData(pickFilterList);
            }
        }
        //接受会员星级
        if (view.getId() == R.id.members_level) {
            mModel.getMemberLevelList(view);
        }
        //货款支付时间
        if (view.getId() == R.id.terms_time) {
            if (TextUtils.isEmpty(mBinding.rules.auctionEndtime.getContent())) {
                MToast.showToast(this, "请选择拍卖结束时间");
                return;
            }
            showTimePop(view);
        }
        //货款支付方式
        if (view.getId() == R.id.terms_payment) {
            mModel.getPaymentList("货款支付方式", view);
        }
        //运输方式
        if (view.getId() == R.id.transport_type) {
            mModel.getTransportType(view);
        }
    }


    @Override
    public void onClick(View v) {
        //提交
        if (v.getId() == R.id.submit) {
            if (TextUtils.isEmpty(SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.LOGIN_TOKEN, ""))) {
                showDialog3();
                return;
            } else {
                submitDataBean();
            }
        }
        //取消
        if (v.getId() == R.id.cancel) {
            initDialog();
        }
        //基础信息新增字段
        if (v.getId() == R.id.auction_basic_field) {
        }
        //标的物详情新增字段
        if (v.getId() == R.id.auction_detailed_field) {
        }
        //拍卖规则新增字段
        if (v.getId() == R.id.auction_rules_field) {
        }
    }

    /**
     * 图文描述模块view初始化
     */
    private void imtvView() {
        GridLayoutManager manager = new GridLayoutManager(this, 4);
        mBinding.detailed.recyclerView.setLayoutManager(manager);
        mPicAdapter = new SelfTeamPicAdapter(this, new ArrayList<>(), 8, manager);
        mBinding.detailed.recyclerView.setHasFixedSize(false);
        mBinding.detailed.recyclerView.addItemDecoration(new GridSpacingItemDecoration(4, ScreenUtils.dip2px(this, 5), true));
        mBinding.detailed.recyclerView.setAdapter(mPicAdapter);
        mPicAdapter.setOnItemClick(new AdapterOnItemClick<String>() {
            @Override
            public void onItemClick(String s, int position) {
                if (TextUtils.isEmpty(s)) {
                    mModel.pictureSelector(mPicAdapter.hasCount(), PictureConfig.CHOOSE_REQUEST);
                } else {
                    List<String> newImg = new ArrayList<>();
                    if (mPicAdapter.getDatas() != null && mPicAdapter.getDatas().size() != 0) {
                        if ("add".equals(mPicAdapter.getDatas().get(mPicAdapter.getDatas().size() - 1))) {
                            for (int i = 0; i < mPicAdapter.getDatas().size(); i++) {
                                if (i != mPicAdapter.getDatas().size() - 1) {
                                    newImg.add(mPicAdapter.getDatas().get(i));
                                }
                            }
                        }
                    }
                    Intent intent = new Intent(getActivity(), PhotoViewActivity.class);
                    intent.putExtra(PhotoViewActivity.KEY_PHOTO_URLS, (Serializable) newImg);
                    intent.putExtra(PhotoViewActivity.KEY_PHOTO_POSITION, position);
                    startActivity(intent);
                }
            }
        });
    }

    //提交数据判断
    private void submitDataBean() {
        if (TextUtils.isEmpty(mBinding.basic.applyUnit.getContent())) {
            MToast.showToast(this, "请选择申请单位");
            return;
        }
        if (TextUtils.isEmpty(mBinding.basic.auctionName.getContent())) {
            MToast.showToast(this, "请输入拍卖名称");
            return;
        } else {
            bean.setName(mBinding.basic.auctionName.getContent());
        }
        if (TextUtils.isEmpty(mBinding.basic.auctionContact.getContent())) {
            MToast.showToast(this, "请输入联系人");
            return;
        } else {
            bean.setContacts(mBinding.basic.auctionContact.getContent());
        }
        if (TextUtils.isEmpty(mBinding.basic.auctionPhone.getContent())) {
            MToast.showToast(this, "请输入联系电话");
            return;
        } else {
            bean.setContactNumber(mBinding.basic.auctionPhone.getContent());
        }
        if (mBinding.basic.auctionPhone.getContent().length() < 7) {
            MToast.showToast(this, "请输入正确联系电话");
            return;
        }
        if (TextUtils.isEmpty(mBinding.basic.address.getContent())) {
            MToast.showToast(this, "请选择地址");
            return;
        }
        if (TextUtils.isEmpty(mBinding.basic.detailedAddress.getContent())) {
            MToast.showToast(this, "请选择详细地址");
            return;
        }
        //基础信息自定义字段
        customfieldbean.setCustomBase(mBinding.basic.auctionBasicField.getCustomFieldViewData());
        if (TextUtils.isEmpty(mBinding.detailed.shopType.getContent())) {
            MToast.showToast(this, "请选择商品类型");
            return;
        }
        if (TextUtils.isEmpty(mBinding.detailed.brand.getContent())) {
            MToast.showToast(this, "请选择品牌");
            return;
        }
        if (TextUtils.isEmpty(mBinding.detailed.measuringUnit.getContent())) {
            MToast.showToast(this, "请输入计量单位");
            return;
        }
        if (TextUtils.isEmpty(mBinding.detailed.auctionNum.getContent())) {
            MToast.showToast(this, "请输入拍卖量");
            return;
        } else {
            bean.setNum(mBinding.detailed.auctionNum.getContent());
        }
        //商品sku属性
        if (isSku) {
            if (TextUtils.isEmpty(mBinding.detailed.specifications.getContent())) {
                MToast.showToast(this, "请选择规格");
                return;
            }
        } else {
            bean.setSkuDetails(new ArrayList<>());
        }
        //图片处理
        if (mPicAdapter.getDatas().size() <= 1) {
            MToast.showToast(this, "请选择商品图");
            return;
        }
        //商品描述
        if (TextUtils.isEmpty(mBinding.detailed.goodsDescribe.getText().toString().trim())) {
            bean.setDetails("");
        } else {
            bean.setDetails(mBinding.detailed.goodsDescribe.getText().toString().trim());
        }
        //标的物详情自定义字段
        customfieldbean.setCustomAuctionInfo(mBinding.detailed.auctionDetailedField.getCustomFieldViewData());
        if (TextUtils.isEmpty(mBinding.rules.isMargin.getContent())) {
            MToast.showToast(this, "请选择是否缴纳保证金");
            return;
        }
        //是否缴纳保证金（1、是,2、否）
        if (rulebean.getChargeCashDeposit().equals("1")) {
            if (TextUtils.isEmpty(mBinding.rules.margin.getText().toString())) {
                MToast.showToast(this, "请输入竞买保证金");
                return;
            } else {
                rulebean.setCashDeposit(mBinding.rules.margin.getText().toString());
            }
            if (TextUtils.isEmpty(mBinding.rules.marginPayment.getContent())) {
                MToast.showToast(this, "请选择保证金支付方式");
                return;
            }
            if (TextUtils.isEmpty(mBinding.rules.marginAccountName.getContent())) {
                MToast.showToast(this, "请输入保证金收款账户名称");
                return;
            } else {
                rulebean.setCashDepositAccountName(mBinding.rules.marginAccountName.getContent());
            }
            if (TextUtils.isEmpty(mBinding.rules.marginBank.getContent())) {
                MToast.showToast(this, "请输入保证金开户行");
                return;
            } else {
                rulebean.setCashDepositBank(mBinding.rules.marginBank.getContent());
            }
            if (TextUtils.isEmpty(mBinding.rules.marginAccount.getContent())) {
                MToast.showToast(this, "请输入保证金收款账号");
                return;
            } else {
                rulebean.setCashDepositAccount(mBinding.rules.marginAccount.getContent());
            }
        }
        if (TextUtils.isEmpty(mBinding.rules.startPrice.getText().toString().trim())) {
            MToast.showToast(this, "请输入起拍价");
            return;
        } else {
            rulebean.setStartPrice(mBinding.rules.startPrice.getText().toString().trim());
        }
        if (TextUtils.isEmpty(mBinding.rules.bidIncrement.getText().toString().trim())) {
            MToast.showToast(this, "请输入加价幅度");
            return;
        } else {
            rulebean.setPriceRange(mBinding.rules.bidIncrement.getText().toString().trim());
        }
        //保留价
        if (TextUtils.isEmpty(mBinding.rules.keepPrice.getText().toString().trim())) {
            rulebean.setReservePrice("");
        } else {
            if (Double.parseDouble(mBinding.rules.keepPrice.getText().toString().trim())>=Double.parseDouble(mBinding.rules.startPrice.getText().toString().trim())){
                rulebean.setReservePrice(mBinding.rules.keepPrice.getText().toString().trim());
            }else {
                MToast.showToast(this, "请调整您的保留价大于等于起拍价");
                return;
            }
        }
        //评估价
        if (TextUtils.isEmpty(mBinding.rules.assessPrice.getText().toString().trim())) {
            rulebean.setEvaluationPrice("");
        } else {
            rulebean.setEvaluationPrice(mBinding.rules.assessPrice.getText().toString().trim());
        }
        if (TextUtils.isEmpty(mBinding.rules.auctionStarttime.getContent().trim())) {
            MToast.showToast(this, "请选择拍卖开始时间");
            return;
        }
        if (TextUtils.isEmpty(mBinding.rules.auctionEndtime.getContent().trim())) {
            MToast.showToast(this, "请选择拍卖结束时间");
            return;
        }
        List<String>  bidderregion = new ArrayList<>();
        List<String> bidderregionname = new ArrayList<>();
        if (listAll!=null&&listAll.size()>0){
            for (PickFilterEntity pickFilterEntity : listAll) {
                bidderregionname.add(pickFilterEntity.getName());
                bidderregion.add(pickFilterEntity.getNo());
            }
            rulebean.setBidderRegion(bidderregion);
            rulebean.setBidderRegionName(bidderregionname);
        }
        if (TextUtils.isEmpty(mBinding.rules.termsPayment.getContent().trim())) {
            MToast.showToast(this, "请选择货款支付方式");
            return;
        }

        if (TextUtils.isEmpty(mBinding.rules.termsAccountName.getContent())) {
            MToast.showToast(this, "请输入货款支付账户名称");
            return;
        } else {
            rulebean.setLoanAccountName(mBinding.rules.termsAccountName.getContent());
        }
        if (TextUtils.isEmpty(mBinding.rules.termsBank.getContent())) {
            MToast.showToast(this, "请输入货款支付开户行");
            return;
        } else {
            rulebean.setLoanBank(mBinding.rules.termsBank.getContent());
        }
        if (TextUtils.isEmpty(mBinding.rules.termsAccount.getContent())) {
            MToast.showToast(this, "请输入货款支付收款账号");
            return;
        } else {
            rulebean.setLoanAccount(mBinding.rules.termsAccount.getContent());
        }
        if (TextUtils.isEmpty(mBinding.rules.transportType.getContent())) {
            MToast.showToast(this, "请选择运输方式");
            return;
        }
        //竞买须知
        if (!TextUtils.isEmpty(mBinding.bidding.biddingInstructions.getText().toString().trim())) {
            AuctionPublishBean.NoticeBean noticeBean = new AuctionPublishBean.NoticeBean();
            noticeBean.setNotice(mBinding.bidding.biddingInstructions.getText().toString().trim());
            bean.setNotice(noticeBean);
        }
        //新增字段
        customfieldbean.setCustomAuctionRule(mBinding.rules.auctionRulesField.getCustomFieldViewData());
        //拍卖规则
        bean.setRule(rulebean);
        //拍卖自定义字段
        bean.setCustomField(customfieldbean);
        if (Long.parseLong(bean.getRule().getAuctionEndTime()) > System.currentTimeMillis() + (60 * 1000 * 5)) {
            for (String data : mPicAdapter.getDatas()) {
                if (!TextUtils.equals(data, "add")) {
                    if (!data.contains("https://")) {//没有上传过的图
                        File file = new File(data);
                        mModel.uploadAvatarFileModel(file, 5);
                    } else {//上传过的图
                        if (files == null) {
                            files = new ArrayList<>();
                        }
                        files.add(data);
                    }
                }
            }
        } else {
            MToast.showToast(this, "请重新输入拍卖结束时间");
        }

    }

    //初始化商品弹窗信息
    private void initPopWindow() {
        if (goodsTypePopWindow == null) {
            goodsTypePopWindow = new GoodsTypePopWindow(this);
        }
        goodsTypePopWindow.setBgView(mBinding.grayLayout);
        goodsTypePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @Override
            public void result(Object key1, Object key2, Object key3) {
                GoodsPublishEntity goodsPublishEntity = (GoodsPublishEntity) key1;
                //一级分类业务名称、业务编号
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid1Name()) && !TextUtils.isEmpty(goodsPublishEntity.getCid1())) {
                    bean.setCidName1(goodsPublishEntity.getCid1Name());
                    bean.setCid1(goodsPublishEntity.getCid1());
                }
                //二级分类业务名称、业务编号
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid2Name()) && !TextUtils.isEmpty(goodsPublishEntity.getCid2())) {
                    bean.setCidName2(goodsPublishEntity.getCid2Name());
                    bean.setCid2(goodsPublishEntity.getCid2());
                }
                //三级分类业务名称、业务编号
                if (!TextUtils.isEmpty(goodsPublishEntity.getCid3Name()) && !TextUtils.isEmpty(goodsPublishEntity.getCid3())) {
                    bean.setCidName(goodsPublishEntity.getCid3Name());
                    bean.setCid(goodsPublishEntity.getCid3());
                }
                mBinding.detailed.shopType.setContent(goodsPublishEntity.getCid1Name() + "/" + goodsPublishEntity.getCid2Name() + "/" + goodsPublishEntity.getCid3Name());
                mBinding.detailed.brand.setContent("");
                bean.setBrandName("");
                bean.setBrandId("");
                mBinding.detailed.measuringUnit.setContent("");
                mBinding.detailed.auctionNum.setContent("");
                bean.setSkuDetails(new ArrayList<>());
                mBinding.detailed.specifications.setContent("");
                mBinding.detailed.measuringUnit.setContent("");
                bean.setUnitName("");
                bean.setUnit("");
                bean.setSkuDetails(new ArrayList<>());
                mModel.getSku(bean.getCid());
            }
        });
    }

    @Override
    public void onBackPressed() {
        initDialog();
    }

    public void initDialog() {
        new CommonDialog(getActivity()).builder().setPositiveButton("确定").setNegativeButton("取消")
                .setTitle("温馨提示")
                .setMsg("此操作将丢失当前表单填写内容，是否继续？")
                .setDialogCallBack(new CommonDialog.DialogCallBack() {
                    @Override
                    public void onRightClick() {
                        finish();
                    }

                    @Override
                    public void onLeftClick() {
                        return;
                    }
                }).show();
    }

    ;

    /**
     * 申请单位
     *
     * @param data
     * @param view
     */
    public void setCompanyList(List<PublishListBean> data, View view) {
        showListPop("申请单位", view, data);
    }

    /**
     * 申请部门
     *
     * @param data
     * @param view
     */
    public void setDepartmentList(List<PublishListBean> data, View view) {
        showListPop("申请部门", view, data);
    }


    /**
     * 地址信息
     *
     * @param data
     */
    public void setAddressList(List<AddressEntity<List<AddressEntity<List<AddressEntity>>>>> data) {
        this.addressEntityList = data;
        initJsonData();
        showCityPop();
    }

    /**
     * 商品类型
     *
     * @param data
     */
    public void showGoodsTypePop(List<MenuEntity<MenuEntity<MenuEntity>>> data) {
        this.goodsTypeEntityList = data;
        if (!goodsTypePopWindow.isShowing()) {
            goodsTypePopWindow.showDownPopwindow(mBinding.grayLayout, true);
        }
        goodsTypePopWindow.setData(goodsTypeEntityList);
    }

    /**
     * 展示商品类型
     */
    private void showGoodsTypePop() {
        if (!goodsTypePopWindow.isShowing()) {
            goodsTypePopWindow.showDownPopwindow(mBinding.grayLayout, true);
        }
    }

    /**
     * 品牌范围
     *
     * @param data
     * @param view
     */
    public void showBrandPop(List<BrandEntity> data, View view) {
        List<PublishListBean> brandList = new ArrayList<>();
        if (data != null && data.size() > 0) {
            for (int i = 0; i < data.size(); i++) {
                List<BrandEntity.BrandChild> childList = data.get(i).getChildList();
                if (childList != null && childList.size() > 0) {
                    for (int j = 0; j < childList.size(); j++) {
                        PublishListBean ismarginlist = new PublishListBean();
                        ismarginlist.setName(childList.get(j).getName() + "");
                        ismarginlist.setId(childList.get(j).getId() + "");
                        brandList.add(ismarginlist);
                    }
                }
            }
        }
        if (brandList.size() > 0) {
            showListPop("选择品牌范围", view, brandList);
        } else {
            MToast.showToast(this, "当前商品没有品牌");
        }
    }

    /**
     * 是否缴纳保证金
     *
     * @param data
     * @param view
     */
    public void setIsmarginList(List<PublishListBean> data, View view) {
        showListPop("是否缴纳保证金", view, data);
    }

    /**
     * 支付方式
     *
     * @param data
     * @param view
     * @param title
     */
    public void setPaymentList(List<PublishListBean> data, View view, String title) {
        showListPop(title, view, data);
    }

    /**
     * 运输方式
     *
     * @param data
     * @param view
     */
    public void setTransportType(List<PublishListBean> data, View view) {
        showListPop("运输方式", view, data);
    }

    /**
     * 上传图片处理
     *
     * @param filePath
     */
    public void uploadAvatarResult(String filePath) {
        if (files == null) {
            files = new ArrayList<>();
            names = new ArrayList<>();
        }
        int indexOf = filePath.lastIndexOf("/");//当前字符最后一次出现的位置
        names.add(filePath.substring(indexOf + 1, filePath.length()));//截取字符串设置
        files.add(filePath);
        if (files != null && files.size() > 0 && files.size() == mPicAdapter.getRealCount()) {
            bean.setImageNames(ListToStringUtils.listToString1(names));
            bean.setImages(ListToStringUtils.listToString1(files));
            bean.setState("1");
            mModel.AddAuction(bean);
        }
    }

    /**
     * 经纬度信息
     *
     * @param data
     */
    public void updateAddress(MapLongAndLatEntity data) {
        if (!TextUtils.isEmpty(data.getLat())) {
            if (!TextUtils.isEmpty(data.getLng())) {
                if (!TextUtils.isEmpty(data.getLat())) {
                    lat = data.getLat();
                } else {
                    lat = "0";
                }
                if (!TextUtils.isEmpty(data.getLng())) {
                    lng = data.getLng();
                } else {
                    lng = "0";
                }
            }
        }
    }

    /**
     * 是否存在sku属性
     *
     * @param data
     */
    public void isSku(List<GetSkuEntity> data) {
        this.skuList = data;
        if (data != null && data.size() > 0) {
            isSku = true;
            mBinding.detailed.llSpecifications.setVisibility(View.VISIBLE);
        } else {
            isSku = false;
            mBinding.detailed.llSpecifications.setVisibility(View.GONE);
        }
    }

    /**
     * 计量单位
     *
     * @param data
     * @param view
     */
    public void setUnitList(List<PublishListBean> data, View view) {
        this.unitList = data;
        showListPop("选择计量单位", view, unitList);
    }

    /**
     * 竞买人身份
     *
     * @param data
     * @param view
     */
    public void setBiddingStatusList(List<PublishListBean> data, View view) {
        showListPop("竞买人身份", view, data);
    }

    /**
     * 是否公示竞买人名称
     *
     * @param data
     * @param view
     */
    public void setBiddingPublicList(List<PublishListBean> data, View view) {
        showListPop("是否公示竞买人名称", view, data);
    }

    /**
     * 会员等级列表
     *
     * @param data
     * @param view
     */
    public void setMemberLevelList(List<PublishListBean> data, View view) {
        showListPop("接受会员星级", view, data);
    }


    /**
     * 竞买人限定
     * @param listBean
     */
    public void setBidderLimitedlicList(List<PublishListBean> listBean) {
        this.SourcesFundingList = listBean;
        if (SourcesFundingList != null && SourcesFundingList.size() > 0) {
            showMultiselect();
        }
    }


    /**
     * 时间选择器
     *
     * @param views
     */
    private void showTimePop(View views) {
        Calendar dayCalendar = Calendar.getInstance();
        dayCalendar.add(Calendar.DAY_OF_MONTH, 0);
        TimePickerView timePicker = new TimePickerBuilder(this, (date, v) -> {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            String format = sdf.format(date);
            Log.e("tag当前选择的时间是：", format + "");
            //拍卖开始时间
            if (views.getId() == R.id.auction_starttime) {
                if (DateUtils.dateTo13Timestamp3(format + ":00") > System.currentTimeMillis()) {
                    mBinding.rules.auctionStarttime.setContent(format + ":00");
                    mBinding.rules.auctionEndtime.setContent("");
                    mBinding.rules.termsTime.setContent("");
                    rulebean.setAuctionStartTime(DateUtils.dateTo13Timestamp3(mBinding.rules.auctionStarttime.getContent()) + "");
                    rulebean.setAuctionEndTime("");
                    rulebean.setLoanPayTime("");
                } else {
                    MToast.showToast(this, "拍卖开始时间必须大于当前时间");
                }
            }
            //拍卖结束时间
            if (views.getId() == R.id.auction_endtime) {
                if (DateUtils.dateTo13Timestamp3(format + ":00") > Long.parseLong(rulebean.getAuctionStartTime())) {
                    mBinding.rules.auctionEndtime.setContent(format + ":00");
                    mBinding.rules.termsTime.setContent("");
                    rulebean.setAuctionEndTime(DateUtils.dateTo13Timestamp3(mBinding.rules.auctionEndtime.getContent()) + "");
                    rulebean.setLoanPayTime("");
                } else {
                    MToast.showToast(this, "拍卖结束时间必须大于拍卖开始时间");
                }
            }
            //货款支付时间
            if (views.getId() == R.id.terms_time) {
                if (DateUtils.dateTo13Timestamp3(format + ":00") > Long.parseLong(rulebean.getAuctionEndTime())) {
                    mBinding.rules.termsTime.setContent(format + ":00");
                    rulebean.setLoanPayTime(DateUtils.dateTo13Timestamp3(mBinding.rules.termsTime.getContent()) + "");
                } else {
                    MToast.showToast(this, "货款支付时间必须大于拍卖结束时间");
                }
            }
        }).setType(new boolean[]{true, true, true, true, true, false})
                .setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setTitleText("请选择时间")
                .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD"))
                .setRangDate(dayCalendar, null)
                .build();
        timePicker.show();
    }


    /**
     * 单列选择器
     *
     * @param title
     * @param inputTextView
     * @param data
     */
    private void showListPop(String title, View inputTextView, List<PublishListBean> data) {
        if (data != null && data.size() > 0) {
            OptionsPickerView<PublishListBean> mCustomerOptions = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {

                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    if (inputTextView.getId() == R.id.apply_unit) {//申请单位
                        mBinding.basic.applyUnit.setContent(data.get(options1).getName());
                        bean.setApplyCompanyName(data.get(options1).getName());
                        bean.setApplyCompany(data.get(options1).getId());
                        mBinding.basic.applyDepartment.setContent("");
                        bean.setApplyDepName("");
                    }
                    if (inputTextView.getId() == R.id.apply_department) {//申请部门
                        mBinding.basic.applyDepartment.setContent(data.get(options1).getName());
                        bean.setApplyDep(data.get(options1).getId());
                        bean.setApplyDepName(data.get(options1).getName());
                    }
                    if (inputTextView.getId() == R.id.brand) {//品牌
                        mBinding.detailed.brand.setContent(data.get(options1).getName());
                        bean.setBrandName(data.get(options1).getName());
                        bean.setBrandId(data.get(options1).getId());
                    }
                    if (inputTextView.getId() == R.id.measuring_unit) {//计量单位
                        mBinding.detailed.measuringUnit.setContent(data.get(options1).getName());
                        bean.setUnitName(data.get(options1).getName());
                        bean.setUnit(data.get(options1).getNo());
                        mBinding.rules.startPriceUnit.setText("元/" + mBinding.detailed.measuringUnit.getContent() + "");
                        mBinding.rules.bidIncrementUnit.setText("元/" + mBinding.detailed.measuringUnit.getContent() + "");
                        mBinding.rules.keepPriceUnit.setText("元/" + mBinding.detailed.measuringUnit.getContent() + "");
                        mBinding.rules.assessPriceUnit.setText("元/" + mBinding.detailed.measuringUnit.getContent() + "");
                    }
                    if (inputTextView.getId() == R.id.is_margin) {//是否缴纳保证金
                        mBinding.rules.isMargin.setContent(data.get(options1).getName());
                        rulebean.setChargeCashDeposit(data.get(options1).getId());
                        if (data.get(options1).getId().equals("1")) {
                            mBinding.rules.llMargin.setVisibility(View.VISIBLE);
                        } else {
                            mBinding.rules.llMargin.setVisibility(View.GONE);
                            //保证金
                            mBinding.rules.margin.setText("");
                            rulebean.setCashDeposit("");
                            //保证金支付方式
                            mBinding.rules.marginPayment.setContent("");
                            rulebean.setCashDepositPayWay("");
                            mBinding.rules.marginAccountName.setContent("");//收款账户名称
                            mBinding.rules.marginBank.setContent("");//开户行
                            mBinding.rules.marginAccount.setContent("");//收款账号

                        }
                    }
                    if (inputTextView.getId() == R.id.margin_payment) {//保证金支付方式
                        if (data.get(options1).getId().equals("2")) {
                            mBinding.rules.marginPayment.setContent(data.get(options1).getName());
                            rulebean.setCashDepositPayWay(data.get(options1).getId());
                            mBinding.rules.llMarginPayment.setVisibility(View.VISIBLE);
                        } else {
                            MToast.showToast(getActivity(), "网上支付暂不可选择");
                        }
                    }
                    if (inputTextView.getId() == R.id.bidding_status) {//竞买人身份
                        mBinding.rules.biddingStatus.setContent(data.get(options1).getName());
                        rulebean.setBidderIdentity(data.get(options1).getId());
                    }
                    if (inputTextView.getId() == R.id.public_bidding_name) {//是否公示竞买人名称
                        mBinding.rules.publicBiddingName.setContent(data.get(options1).getName());
                        rulebean.setBidderNameIdentity(data.get(options1).getId());
                    }
                    if (inputTextView.getId() == R.id.members_level) {//接受会员星级
                        mBinding.rules.membersLevel.setContent(data.get(options1).getName());
                        rulebean.setMemberLevel(data.get(options1).getId());
                    }
                    if (inputTextView.getId() == R.id.terms_payment) {//货款支付方式
                        if (data.get(options1).getId().equals("2")) {
                            mBinding.rules.termsPayment.setContent(data.get(options1).getName());
                            rulebean.setLoanPayWay(data.get(options1).getId());
                            mBinding.rules.llTermsPayment.setVisibility(View.VISIBLE);
                        } else {
                            MToast.showToast(getActivity(), "网上支付暂不可选择");
                        }
                    }
                    if (inputTextView.getId() == R.id.transport_type) {//运输方式
                        mBinding.rules.transportType.setContent(data.get(options1).getName());
                        rulebean.setTransportWay(data.get(options1).getId());
                    }
                }
            }).setCancelColor(Color.parseColor("#666666"))
                    .setSubCalSize(15)
                    .setTitleColor(Color.parseColor("#969696")).setTitleSize(15)
                    .setSubmitColor(Color.parseColor("#5792FD")).build();
            mCustomerOptions.setTitleText(title);
            mCustomerOptions.setPicker(data);
            mCustomerOptions.setSelectOptions(0);
            mCustomerOptions.show();
        }
    }

    /**
     * 城市选择器
     */
    public void showCityPop() {
        //条件选择器
        CityPickView cityOption = new CityPickBuilder(this, (options1, options2, options3, v) -> {
            String areaName;
            if (opt3.get(options1).get(options2).get(options3) == null) {
                areaName = "";
                bean.setArea("");
            } else {
                areaName = opt3.get(options1).get(options2).get(options3).getName();
                cityPosition3 = options3;
                bean.setArea(opt3.get(options1).get(options2).get(options3).getNo());
            }
            String provinceName = addressEntityList.get(options1).getName();
            String cityName = opt2.get(options1).get(options2).getName();
            if (!TextUtils.isEmpty(cityName)) {
                if (!TextUtils.isEmpty(areaName)) {
                    mBinding.basic.address.setContent(provinceName + "/" + cityName + "/" + areaName);
                } else {
                    mBinding.basic.address.setContent(provinceName + "/" + cityName);
                }
            } else {
                mBinding.basic.address.setContent(provinceName);
            }
            bean.setProvince(addressEntityList.get(options1).getId());
            bean.setCity(opt2.get(options1).get(options2).getNo());
            mModel.getLocationLL(bean.getProvince(), bean.getCity(), bean.getArea());
            mBinding.basic.detailedAddress.setContent("");
        }).setCancelText("取消").setSubCalSize(15)
                .setCancelColor(Color.parseColor("#666666"))
                .setSubmitText("确定")
                .setSubmitColor(Color.parseColor("#5792FD")).build();
        cityOption.setPicker(addressEntityList, opt2, opt3);
        cityOption.setSelectOptions(cityPosition1, cityPosition2, cityPosition3);
        cityOption.show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == 255) {
                if (data == null) {
                    return;
                }
                double lat = data.getDoubleExtra(AuctionMapAddressActivity.LATITUDE, 0);
                double lon = data.getDoubleExtra(AuctionMapAddressActivity.LONGTITUDE, 0);
                String address = data.getStringExtra(AuctionMapAddressActivity.CURRENT_POSITION);
                mBinding.basic.detailedAddress.setContent(address + "");
                bean.setAddress(address);
                bean.setLat(lat+"");
                bean.setLng(lon+"");
            }
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {
                List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                mPicAdapter.setPicData(selectList);
            }
            if (requestCode == SKULIST) {
                List<AuctionPublishBean.SkuDetailsBean> SkuDetailsBean = new ArrayList<>();
                skuList = (List<GetSkuEntity>) data.getSerializableExtra("data");
                for (GetSkuEntity getSkuEntity : skuList) {
                    AuctionPublishBean.SkuDetailsBean sku = new AuctionPublishBean.SkuDetailsBean();
                    sku.setAttribute(getSkuEntity.getId());
                    sku.setAttributeName(getSkuEntity.getParamData());
                    sku.setVal(getSkuEntity.getText() + "");
                    sku.setValId(getSkuEntity.getTextid() + "");
                    SkuDetailsBean.add(sku);
                }
                bean.setSkuDetails(SkuDetailsBean);
                mBinding.detailed.specifications.setContent("已填写");
            }
        }
    }

    //组装省市区数据信息
    private void initJsonData() {
        for (int i = 0; i < addressEntityList.size(); i++) {
            ArrayList areaList = new ArrayList<>();
            opt2.add(addressEntityList.get(i).getChildren());
            for (int j = 0; j < addressEntityList.get(i).getChildren().size(); j++) {
                List<AddressEntity> cityAreaList = new ArrayList<>();
                List<AddressEntity> children = addressEntityList.get(i).getChildren().get(j).getChildren();
                if (children == null || children.size() == 0) {
                    cityAreaList.add(null);
                } else {
                    cityAreaList.addAll(children);
                }
                areaList.add(cityAreaList);
            }
            opt3.add(areaList);
        }
    }

    //未登录弹框跳转认证
    public void showDialog3() {
        View view = View.inflate(this, R.layout.dialog_two_btn, null);
        RoundCornerDialog roundCornerDialog = new RoundCornerDialog(getActivity(), 0, 0, view, R.style.RoundCornerDialog);
        roundCornerDialog.show();
        roundCornerDialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        TextView tv_message = (TextView) view.findViewById(R.id.tv_message);
        tv_title.setVisibility(View.VISIBLE);
        tv_title.setText("温馨提示");
        TextView tv_logout_confirm = (TextView) view.findViewById(R.id.tv_logout_confirm);
        tv_logout_confirm.setText("确定");
        TextView tv_logout_cancel = (TextView) view.findViewById(R.id.tv_logout_cancel);
        tv_message.setText("未登录，请先登录。");
        //确定
        tv_logout_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityJump.startActivity(PathLogin.VerificationCodeLoginActivity);
                roundCornerDialog.dismiss();
            }
        });
        //取消
        tv_logout_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                roundCornerDialog.dismiss();
            }
        });
    }

    /**
     * 竞买人限定弹窗设置
     */
    private void showMultiselect() {
        final Dialog dialog = new Dialog(this, R.style.DialogTheme);
        //2、设置布局
        View view = View.inflate(this, R.layout.sources_fund_view, null);
        TextView tvtitle = view.findViewById(R.id.tv_title);
        tvtitle.setText("请选择竞买人限定");
        RecyclerView listView = view.findViewById(R.id.listView);
        dialog.setContentView(view);
        Window window = dialog.getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置弹出动画
        window.setWindowAnimations(R.style.ActionSheetDialogAnimation);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.show();
        //取消
        dialog.findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        //确定
        dialog.findViewById(R.id.determine).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < sourcesFundAdapter.getDatas().size(); i++) {
                    if (sourcesFundAdapter.getDatas().get(i).isSelected()){
                        sb.append(sourcesFundAdapter.getDatas().get(i).getName()).append(",");
                    }
                }
                if (!TextUtils.isEmpty(sb.toString())){
                    String str = sb.substring(0, sb.toString().length() - 1);
                    mBinding.rules.bidderLimited.setContent(str);
                    List<String> sign = new ArrayList<>();
                    if (TextUtils.equals(str,"限会员")){
                        sign.add("2");
                        mBinding.rules.acceptArea.setVisibility(View.GONE);//接受企业注册地区
                        mBinding.rules.membersLevel.setVisibility(View.VISIBLE);//接受会员星级
                        mBinding.rules.membersLevel.setContent("不限");
                        rulebean.setMemberLevel("0");
                    }
                    if (TextUtils.equals(str,"限企业注册地区")){
                        sign.add("1");
                        mBinding.rules.acceptArea.setVisibility(View.VISIBLE);//接受企业注册地区
                        mBinding.rules.membersLevel.setVisibility(View.GONE);//接受会员星级
                        mBinding.rules.membersLevel.setContent("");
                        rulebean.setMemberLevel("");
                    }
                    if (TextUtils.equals(str,"限会员,限企业注册地区")){
                        sign.add("1");
                        sign.add("2");
                        mBinding.rules.acceptArea.setVisibility(View.VISIBLE);//接受企业注册地区
                        mBinding.rules.membersLevel.setVisibility(View.VISIBLE);//接受会员星级
                        mBinding.rules.membersLevel.setContent("不限");
                        rulebean.setMemberLevel("0");
                    }
                    rulebean.setBidderSign(sign);
                }else {
                    mBinding.rules.bidderLimited.setContent("");
                    mBinding.rules.acceptArea.setVisibility(View.GONE);//接受企业注册地区
                    mBinding.rules.membersLevel.setVisibility(View.GONE);//接受会员星级
                    mBinding.rules.membersLevel.setContent("");
                    rulebean.setMemberLevel("");
                    rulebean.setBidderSign(new ArrayList<>());
                }
                dialog.dismiss();
            }
        });
        sourcesFundAdapter = new SourcesFundAdapter(this, SourcesFundingList);
        listView.setLayoutManager(new LinearLayoutManager(this));
        listView.setAdapter(sourcesFundAdapter);
    }

    /**
     * 发布成功处理
     */
    public void setAddAuction(String msg) {
        MToast.showToast(this, "发布拍卖信息成功！");
        finish();
    }

    /**
     * 接收的注册地区信息
     * @param data
     */
    public void setAcceptAreaList(List<PickFilterEntity<List<PickFilterEntity>>> data) {
        this.pickFilterList = data;
        TwoLevelData(data);
    }

    /**
     * 接受企业注册地区
     * @param data
     */
    private void TwoLevelData(List<PickFilterEntity<List<PickFilterEntity>>> data) {
        TwoLevelMultipleChoiceWindow window = new TwoLevelMultipleChoiceWindow(this);
        window.setTitle("接受企业注册地区");
        window.setBgView(mBinding.grayLayout);
        window.setIsOneSelete(true);
        window.setOnResultClick(new TwoLevelMultipleChoiceWindow.OnResultClick() {
            @Override
            public void result(List<PickFilterEntity> list) {
                for (PickFilterEntity pickFilterEntity : list) {
                    if (!listaddress.contains(pickFilterEntity.getName())) {
                        listaddress.add(pickFilterEntity.getName());
                        listAll.add(pickFilterEntity);
                    }
                }
                if (listAll.size()>0){
                    mBinding.rules.flexLayout.removeAllViews();
                    mBinding.rules.flexLayout.setVisibility(View.VISIBLE);
                }else {
                    mBinding.rules.flexLayout.removeAllViews();
                    mBinding.rules.flexLayout.setVisibility(View.GONE);
                }
                AddressViewData(listAll);
            }
        });
        window.setData(data);
        window.showPopwindow(mBinding.rules.acceptArea, Gravity.BOTTOM, 0, 0);
    }

    private void AddressViewData(List<PickFilterEntity> listAll) {
        for (PickFilterEntity entity : listAll){
            View view = LayoutInflater.from(this).inflate(R.layout.item_addresslist_src,  mBinding.rules.flexLayout, false);
            TextView tvName = view.findViewById(R.id.tvName);
            tvName.setText(entity.getName());
            tvName.setOnClickListener(v -> {
                if (listAll!=null&&listAll.size()>0){
                    listAll.remove(entity);
                    mBinding.rules.flexLayout.removeView(view);
                    if (listAll.size()<=0){
                        mBinding.rules.flexLayout.setVisibility(View.GONE);
                    }
                }
            });
            mBinding.rules.flexLayout.addView(view);
        }
    }
}
